﻿<Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Reference.Apps"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Interactivity="using:Microsoft.Xaml.Interactivity" xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
    x:Class="Reference.Apps.CodeView"
    mc:Ignorable="d"
    Background="{StaticResource ApplicationPageBackgroundBrush}" DataContext="{Binding Main, Mode=OneWay, Source={StaticResource VMLocator}}" RequestedTheme="Light">
    <Page.BottomAppBar>
        <CommandBar RequestedTheme="Light">
            <AppBarButton x:Uid="WP8ZoomCodeAppBarButton" Icon="FullScreen" Label="zoom" x:Name="ZoomButton" Click="ZoomButton_Click">
            </AppBarButton>
			<AppBarButton x:Uid="WP8DecreaseFontSizeAppBarButton" Icon="FontDecrease" Label="AppBarButton">
				<Interactivity:Interaction.Behaviors>
					<Core:EventTriggerBehavior EventName="Click">
						<Core:InvokeCommandAction Command="{Binding DecrementFontSizeCommand, Mode=OneWay}"/>
					</Core:EventTriggerBehavior>
				</Interactivity:Interaction.Behaviors>
			</AppBarButton>
			<AppBarButton x:Uid="WP8IncreaseFontSizeAppBarButton" Icon="FontIncrease" Label="AppBarButton">
				<Interactivity:Interaction.Behaviors>
					<Core:EventTriggerBehavior EventName="Click">
						<Core:InvokeCommandAction Command="{Binding IncrementFontSizeCommand, Mode=OneWay}"/>
					</Core:EventTriggerBehavior>
				</Interactivity:Interaction.Behaviors>
			</AppBarButton>
        </CommandBar>
    </Page.BottomAppBar>

    <Interactivity:Interaction.Behaviors>
        <Core:EventTriggerBehavior EventName="Loaded">
            <Core:InvokeCommandAction Command="{Binding GetCodeViewCommand, Mode=OneWay}"/>
        </Core:EventTriggerBehavior>
    </Interactivity:Interaction.Behaviors>

    <Grid x:Name="LayoutRoot" DataContext="{Binding Main.CodeViewSnippet, Source={StaticResource VMLocator}}">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualState x:Name="CodeFullscreen">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="CodeGrid">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Default"/>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid HorizontalAlignment="Left"  Grid.RowSpan="2" VerticalAlignment="Top"/>
        <!-- Title Panel -->
        <StackPanel Grid.Row="0" Margin="19,0,0,0">
            <TextBlock Text="{Binding CodeGroupName, Converter={StaticResource UpperConverter}}" Style="{ThemeResource TitleTextBlockStyle}" Margin="0,12,0,0" Foreground="{StaticResource ApplicationContrastBackgroundBrush}"/>
        </StackPanel>

        <!--TODO: Content should be placed within the following grid-->
        <Grid Grid.Row="1" x:Name="ContentRoot" Margin="0,9.5,0,0">
            <Hub Header="{Binding Title, Converter={StaticResource LowerConverter}}" RequestedTheme="Light">
                <HubSection x:Uid="NotesHubSection" Header="Notas" Foreground="{StaticResource ApplicationContrastBackgroundBrush}">
                    <DataTemplate>
                        <Grid>
                            <ScrollViewer>
                                <StackPanel >
                                    <TextBlock Style="{StaticResource SubheaderTextBlockStyle}" TextWrapping="Wrap" Text="{Binding Notes}"/>
                                </StackPanel>
                            </ScrollViewer>
                        </Grid>

                    </DataTemplate>
                </HubSection>
                <HubSection Header="{Binding Lang, Converter={StaticResource Lang2Language}}" Foreground="{StaticResource ApplicationContrastBackgroundBrush}" >
                    <DataTemplate>
                        <Grid>
                            <ScrollViewer>
                                <Border Background="{Binding Lang, Converter={StaticResource Lang2Brush}}">
                                    <Border Background="White"  Margin="0,15,0,0">
                                        <TextBlock Text="{Binding Code}" FontFamily="Courier New" FontSize="{Binding Main.CodeFontSize, Source={StaticResource VMLocator}}" Margin="5" />
                                    </Border>
                                </Border>
                            </ScrollViewer>
                        </Grid>
                    </DataTemplate>
                </HubSection>
                <HubSection x:Uid="DummyHubSection" Header="HubSection 2">
                    <DataTemplate>
                        <Grid/>
                    </DataTemplate>
                </HubSection>
            </Hub>

        </Grid>
        <Grid x:Name="grid" Grid.RowSpan="2" Background="{StaticResource ApplicationContrastBackgroundTransparetBrush}" DataContext="{Binding Source={StaticResource VMLocator}}" Visibility="{Binding Main.IsBusy, Converter={StaticResource BoolToVisibilityConverter}}">
            <!--<Grid Grid.RowSpan="2" Background="{StaticResource ApplicationContrastBackgroundTransparetBrush}">-->
            <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                <ProgressBar Height="10" Width="{Binding Width, ElementName=grid}" IsIndeterminate="True"/>
                <TextBlock HorizontalAlignment="Center" Text="Cargando..." Foreground="White" />
            </StackPanel>
        </Grid>
        <Grid x:Name="CodeGrid" Grid.RowSpan="2" Visibility="Collapsed">
            <ScrollViewer>
                <Border Background="{Binding Lang, Converter={StaticResource Lang2Brush}}">
                    <Border Background="White"  Margin="0,15,0,0">
                        <TextBlock x:Name="textBlock" Text="{Binding Code}" FontFamily="Courier New" FontSize="{Binding Main.CodeFontSize, Source={StaticResource VMLocator}}" Margin="5" Foreground="{StaticResource ApplicationContrastBackgroundBrush}" TextWrapping="WrapWholeWords" />
                    </Border>
                </Border>
            </ScrollViewer>
        </Grid>
    </Grid>
</Page>
